package com.wellsfargo.bm;

import java.util.Stack;

public class MyStack extends Stack<Integer>{

	Stack<Integer> maxs;

	MyStack(){
		maxs=new Stack<Integer>();
	}
	public void push(int val){
		if(super.isEmpty())
			maxs.push(val);
		if(val>=maxs.peek())
			maxs.push(val);
		super.push(val);
	}

	public Integer pop(){
		if(super.isEmpty())
			try {
				throw new Exception();
			} catch (Exception e) {
				e.printStackTrace();
			}
		Integer val=super.pop();
		if(val==maxs.peek())
			maxs.pop();
		return val;
	}

	public Integer getMax(){
		if(maxs.isEmpty())
			try {
				throw new Exception();
			} catch (Exception e) {
				e.printStackTrace();
			}

		return maxs.peek();
	}
}
